package com.cin.cma.server.pos.controller;


import com.cin.cma.common.model.ApiResponse;
import com.cin.cma.common.model.finixx.base.BaseResponse;
import com.cin.cma.common.model.finixx.request.*;
import com.cin.cma.common.model.finixx.response.VoucherPayPolicyResponse;
import com.cin.cma.common.model.finixx.response.VoucherRedeemResponse;
import com.cin.cma.common.model.finixx.response.VoucherResponse;
import com.cin.cma.common.model.finixx.response.VoucherTempLockResponse;
import com.cin.cma.server.pos.service.IVoucherService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @Date：2024/7/19 18:38
 */
@RestController
@RequestMapping("voucher")

public class VoucherController {
    @Autowired
    private IVoucherService voucherService;

    /**
     * 退款兑换券(兑换券退票时需手动退券)
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("refund")
    public ApiResponse<BaseResponse> refund(@RequestBody @Valid VoucherRefundRequest model) throws Exception {
        return ApiResponse.success(voucherService.refund(model));
    }

    /**
     * 获取兑换券信息
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("get")

    public ApiResponse<VoucherResponse> get(@RequestBody @Valid VoucherGetRequest model) throws Exception {
        return ApiResponse.success(voucherService.get(model));
    }

    /**
     * 临时锁定券
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("tempLock")

    public ApiResponse<VoucherTempLockResponse> tempLock(@RequestBody @Valid VouVoucherTempLockRequest model) throws Exception {
        return ApiResponse.success(voucherService.tempLock(model));
    }

    /**
     * 券兑换接口
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("redeem")

    public ApiResponse<VoucherRedeemResponse> redeem(@RequestBody @Valid VoucherRedeemRequest model) throws Exception {
        return ApiResponse.success(voucherService.redeem(model));
    }

    /**
     * 券兑换回滚
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("redeemRollback")

    public ApiResponse<BaseResponse> redeemRollback(@RequestBody @Valid VoucherRedeemRollbackRequest model) throws Exception {
        return ApiResponse.success(voucherService.redeemRollback(model));
    }

    /**
     * 券政策获取
     *
     * @param model
     * @return
     */
    @ResponseBody
    @PostMapping("getPayPolicy")

    public ApiResponse<VoucherPayPolicyResponse> getPayPolicy(@RequestBody @Valid VoucherPayPolicyRequest model) throws Exception {
        return ApiResponse.success(voucherService.getPayPolicy(model));
    }
}
